/*
 * @Author: 赵成功a 3063126760@qq.com
 * @Date: 2024-12-21 19:41:02
 * @LastEditors: 赵成功a 3063126760@qq.com
 * @LastEditTime: 2024-12-26 00:10:32
 * @FilePath: /linux-learning/12-21/Server.cpp
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include "comm.hpp"
#include "log.hpp"
int main()
{
    Init init;
    Log log;
    string s;
    log.Enable(Classfile);
    int fd = open(FIFO_FIFE, O_WRONLY | O_APPEND); /// 打开管道文件
    if (fd < 0){
        log.logmessage(Fatal,"error string: %s, error code: %d", strerror(errno), errno);
        exit(FIFO_OPEN_ERR);
    }
    log.logmessage(Info, "server open file done, error string: %s, error code: %d", strerror(errno), errno);
    log.logmessage(Warning, "server open file done, error string: %s, error code: %d", strerror(errno), errno);
    log.logmessage(Fatal, "server open file done, error string: %s, error code: %d", strerror(errno), errno);
    log.logmessage(Debug, "server open file done, error string: %s, error code: %d", strerror(errno), errno);

    while (true){
        sleep(1);
        cout << "Server says@";
        getline(cin, s);
        write(fd, s.c_str(), s.size()); // 这里要小心，这里的写入要按照写入的多少去写进去，不然会出现读写不灵敏等问题
    }
    close(fd); // 关闭文件
}